﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace t4tesk1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //注册页面
            register ter = new register();
            ter.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //判断协议是否被勾选
            if (checkBox1.Checked)
            {
                SqlDataReader reader;
                string sql = string.Format("select * from User1");
                reader = DBHelper.Select(sql);
                while (reader.Read())
                {
                    //账号和密码是否正确
                    if (textBox1.Text == reader["UserName"].ToString() && textBox2.Text == reader["UserPwd"].ToString())
                    {
                        game me = new game();
                        me.Show();
                        this.Hide();
                        break;
                    }
                    else
                    {
                        MessageBox.Show("账号或密码错误！！！");
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("未勾选同意协议！！");
            }
            
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "请输入密码";
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            /*if (textBox1.Text == "请输入账号")
            {
                textBox1.Text = "";
            }*/
                
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            
            /*if (textBox1.Text == "")
            {
                MessageBox.Show("请输入账号");
                textBox1.Focus();
            }*/
        }

        private void textBox2_Enter(object sender, EventArgs e)
        {
            if (textBox2.Text == "请输入密码")
            {
                textBox2.Text = "";
            }

        }

        private void textBox2_Leave(object sender, EventArgs e)
        {

            if (textBox2.Text == "")
            {
                MessageBox.Show("请输入密码");
                textBox2.Focus();
            }
        }
    }
}
